<template>
	<view>
		<qf-image-cropper ref="qfImageCropper" :src="src" :width="width" :height="height" @crop="handleCrop"></qf-image-cropper>
	</view>
</template>

<script>
	import QfImageCropper from '@/uni_modules/qf-image-cropper/components/qf-image-cropper/qf-image-cropper.vue';
	const httpRequest = require("@/common/httpRequest.js")
	export default {
		components: {
			QfImageCropper
		},
		data() {
			return {
				src:"",
				width:"",
				height:"",
				type:1,//1添加图片，2编辑图片,3资料图片添加，4资料图片编辑
				yt_image:"",
			}
		},
		onLoad(options) {
			let data = JSON.parse(decodeURIComponent(options.msg));
			console.log(data);
			this.src = data.src
			this.width = Number(data.width)
			this.height = Number(data.height)
			this.type = data.type
			if(data.type==1 || data.type==3){
				this.getyimage()
			}
		},
		methods: {
			getyimage() {
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.uploadFile('/api/common/upload', this.src).then(res => {
					uni.hideLoading()
					this.yt_image = res.url
				}).catch(err => {});
			},
			handleCrop(e) {
				uni.showLoading({
					mask:true,
					title:"请稍后"
				})
				httpRequest.uploadFile('/api/common/upload', e.tempFilePath).then(res => {
					uni.hideLoading()
					let data = {
						image:res.url,
						image_text:res.fullurl,
						type:this.type,
						yt_image:this.yt_image
					}
					uni.$emit("changeImg",data)
					uni.navigateBack(1)
				}).catch(err => {});
			}
 		}
	}
</script>

<style lang="scss" scoped>

</style>
